//
//  SRSportView.m
//  SportRing
//
//  Created by icelee on 14-10-27.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRSportView.h"
#import "UICountingLabel.h"
#import "HKCircleChartView.h"
#import "SRAimSportView.h"

@implementation SRSportViewModel

- (id)initWithSteps:(float)steps calorie:(float)calorie distance:(float)distance aimModel:(SRAimSportViewModel *)aimModel
{
    
    self = [super init];
    
    if (self) {
        self.steps = steps;
        self.calorie = calorie;
        self.distance = distance;
        self.aimSportViewModel = aimModel;
    }
    return self;
}

- (NSString *)description {
    
    return [NSString stringWithFormat:@"%f %d %f",self.calorie,self.steps,self.distance];
}

@end

@interface SRSportView ()

@property (nonatomic, weak)IBOutlet UIImageView *stepsImageView;
@property (nonatomic, weak)IBOutlet UIImageView *calorieImageView;
@property (nonatomic, weak)IBOutlet UIImageView *distanceImageView;
@property (nonatomic, weak)IBOutlet UICountingLabel *stepsCountingLabel;
@property (nonatomic, weak)IBOutlet UICountingLabel *calorieCountingLabel;
@property (nonatomic, weak)IBOutlet UICountingLabel *distanceCountingLabel;
@property (nonatomic, weak)IBOutlet UILabel *stepsTextLabel;
@property (nonatomic, weak)IBOutlet UILabel *calorieTextLabel;
@property (nonatomic, weak)IBOutlet UILabel *distanceTextLabel;
@property (nonatomic, weak)IBOutlet UIButton *sportDetail;

@property (nonatomic, weak)IBOutlet SRAimSportView *aimSportView;

- (void)setupLabelColors;

@end

@implementation SRSportView

- (void)awakeFromNib{
    [super awakeFromNib];
    [self setupLabelColors];
    self.stepsCountingLabel.format = @"%d";
    self.calorieCountingLabel.format = @"%d";
    self.distanceCountingLabel.format = @"%.1f";
    [_sportDetail addTarget:self action:@selector(goToDetail) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setupLabelColors{
    
    [self.stepsCountingLabel setTextColor:[UIColor colorWithRed:246.0/255.0 green:99.0/255.0 blue:11.0/255.0 alpha:1.0]];
    [self.calorieCountingLabel setTextColor:[UIColor colorWithRed:116.0/255.0 green:169.0/255.0 blue:31.0/255.0 alpha:1.0]];
    [self.distanceCountingLabel setTextColor:[UIColor colorWithRed:116.0/255.0 green:169.0/255.0 blue:31.0/255.0 alpha:1.0]];
    [self.stepsTextLabel setTextColor:[UIColor colorWithRed:246.0/255.0 green:99.0/255.0 blue:11.0/255.0 alpha:1.0]];
    [self.calorieTextLabel setTextColor:[UIColor colorWithRed:116.0/255.0 green:169.0/255.0 blue:31.0/255.0 alpha:1.0]];
    [self.distanceTextLabel setTextColor:[UIColor colorWithRed:116.0/255.0 green:169.0/255.0 blue:31.0/255.0 alpha:1.0]];
}

- (void)setSRSportViewDataWithModel:(SRSportViewModel*)srSportViewModel{
    
    self.stepsCountingLabel.method = UILabelCountingMethodEaseIn;
    self.calorieCountingLabel.method = UILabelCountingMethodEaseIn;
    self.distanceCountingLabel.method = UILabelCountingMethodEaseIn;
    
    [self.stepsCountingLabel countFrom:0 to:srSportViewModel.steps withDuration:1.0];
    [self.calorieCountingLabel countFrom:0 to:srSportViewModel.calorie withDuration:1.0];
    [self.distanceCountingLabel countFrom:0 to:srSportViewModel.distance withDuration:1.0];
    
    [self.stepsCountingLabel setCompletionBlock:^{
        
        self.stepsCountingLabel.text = [NSString stringWithFormat:@"%d",srSportViewModel.steps];
    }];
    [self.calorieCountingLabel setCompletionBlock:^{
        
        self.calorieCountingLabel.text = [NSString stringWithFormat:@"%d",(int)srSportViewModel.calorie];
    }];
    [self.distanceCountingLabel setCompletionBlock:^{
        
        self.distanceCountingLabel.text = [NSString stringWithFormat:@"%.1lf",srSportViewModel.distance];
    }];
    
    [self.aimSportView setSRAimSportViewDataWithModel:srSportViewModel.aimSportViewModel];
    
}

- (void)goToDetail
{
    if (_srSportDelegate && [_srSportDelegate respondsToSelector:@selector(onedaySportDetail:)])
    {
        [_srSportDelegate onedaySportDetail:self];
    }
}

@end
